let startY = 0 // 手指起始的坐标
let moveY = 0 // 手指移动的坐标
let moveDistance = 0 // 手指移动的距离

Page({
  /**
   * 页面的初始数据
   */
  data: {
    coverTransform: 'translateY(0)',
    coveTransition: '',
    userInfo: {},
    recentPlayList: [],
  },
  onLoad() {
    this.setData({
      userInfo: wx.getStorageSync('userInfo'),
    })
    this.getUserRecentPlayList(this.data.userInfo.userId)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  handleTouchStart(event) {
    this.setData({
      coveTransition: '',
    })
    startY = event.touches[0].clientY
  },
  handleTouchMove(event) {
    moveY = event.touches[0].clientY
    moveDistance = moveY - startY
    if (moveDistance <= 0) return
    if (moveDistance >= 80) {
      moveDistance = 80
    }
    this.setData({
      coverTransform: `translateY(${moveDistance}rpx)`,
    })
  },
  handleTouchEnd() {
    this.setData({
      coverTransform: `translateY(0)`,
      coveTransition: 'transform 0.5s linear',
    })
  },
  async getUserRecentPlayList(userId) {
    let recentPlayList = await wx.$http.get('/user/record', {
      uid: userId,
      type: 1,
    })
    let i = 0
    if (recentPlayList.weekData.length !== 0 &&recentPlayList.weekData.length <= 10) {
      recentPlayList = recentPlayList.weekData.map((value) => {
        value.id = i++
        return value
      })
    } else {
      recentPlayList = recentPlayList.weekData.slice(0,10).map((value) => {
        value.id = i++
        return value
      })
    }
    this.setData({
      recentPlayList
    })
  },
  iconnav(){
    wx.navigateTo({
      url: '/pages/iconpage/iconpage'
    });
  },
  toLogin(){
    wx.navigateTo({
      url: '/pages/logs/logs'
    });
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
})
